package chapter8;


import chapter5.dao.AdminDao;
import chapter5.dao.impl.AdminDaoImpl;
import chapter5.service.AdminService;
import chapter5.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/shangc")
public class scServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置请求编码格式
        request.setCharacterEncoding("utf-8");
        //设置响应的格式
        response.setContentType("text/html;charset=utf-8");
        //设置响应的编码格式
        response.setCharacterEncoding("utf-8");
        PrintWriter out=response.getWriter();
        String sc=request.getParameter("id");
        AdminService admin=new AdminServiceImpl();
        int count=admin.delete(sc);
        if (count>0){
            out.println("<script type=\"text/javascript\">\n" +
                    "        alert(\"删除成功！\");\n" +
                    "        location.href=\"http://localhost:8080/untitled1_war_exploded/eee\";\n" +
                    "    </script>");
        }

            out.flush();



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
